/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package net.tygzs.minerpg.keyBoardListener;

import java.io.IOException;
import java.net.ServerSocket;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.tygzs.minerpg.Main;
import org.bukkit.Bukkit;

/**
 *
 * @author thtTNT
 */
public class keyBoardListener
{

    private static boolean isEnable = false;
    private static int task;
    public static ServerSocket server;

    public static void start()
    {
        if (isEnable)
        {
            Bukkit.getScheduler().cancelTask(task);
        }
        keyBoardListener.task = Bukkit.getScheduler().runTaskAsynchronously(Main.getPlugin(), new Runnable()
        {

            @Override
            public void run()
            {

                try
                {
                    server = new ServerSocket(Main.getPlugin().getConfig().getInt("ListeningPort"));
                    keyBoardListener.isEnable = true;
                    Main.getPlugin().getLogger().info("键盘监听系统启动成功");
                    server.accept();
                } catch (IOException ex)
                {
                    Main.getPlugin().getLogger().info("监听端口打开失败,键盘监听系统失效");
                }
            }
        }).getTaskId();
    }
}
